<?php
namespace Admin\Controller;

class CagetroyController extends AdminController {

    public function index(){
    	$model = M('tags');
    	$data = $model->order('id desc')->select();
		//$this->assign('title','学员数据修改');
		$this->assign('data',$data);
		$this->display();

       
    }
    public function add(){
    	$model = M('tags');
    	$pid = I('get.id/d',0);
    	$pid = (int)$pid;
    	//var_dump($pid);exit;
    	$result = $model->find($pid);
    	if($pid==0){
    		$path = '0,';
    	}else{

    		$path = $result['path'].$result['id'].',';

    	}
    	

    	$this->assign('pid',$pid);
    	$this->assign('path',$path);
    	//var_dump($path);
    	$this->display();

    	
    	
    	
    	
    }
    public function adder(){

    	$model = M('tags');
    	//var_dump($_POST);
    	$model->create();
    	if($model->add()>0){

    		$this->success('恭喜你添加成功！',U('index'));
    	}else{
    		$this->error('添加失败！');
    	}




    }
    public function delete(){
    	$id = I('get.id/d',0);
		//删除
		if(M('tags')->delete($id) > 0 ){
			$this->success('恭喜你删除成功！',U('index'));
			
		} else {
			$this->error('删除失败！');
		
		}
	}
	public function edit(){

		$id = I('get.id/d',0);
		//var_dump($id);
		$model = M('tags');
		$data = $model->find($id);
		//var_dump($data);
		if(!$data){
			$this->error('暂无数据');
			exit;
		}

		//$this->assign('title','学员数据修改');
		$this->assign('data',$data);
		$this->display();
		
	}
	public function update(){
		if(!IS_POST){
			$this->redirect('index');
			exit;
		}

		$model = M('tags');
		$model->create();
		if($model->save()>0){

			$this->success('恭喜你修改成功！',U('index'));

		}else {
			$this->error('修改失败！');
		
		}

	}
	public function change(){
		
		$id = I('get.id/d',0);
		$model = M('tags');
		$data=$model->find($id);
		// var_dump($data['display']);
		if($data['display']=='0'){
			$data['display']='1';
		}else{
			$data['display']='0';
		}

		if($model->save($data)){

			$this->success('恭喜你修改成功！',U('index'));

		}else {
			$this->error('修改失败！');
		
		}

    }
}
